package icraf.carbon.gui;

import icraf.carbon.core.AbacusContainer;
import icraf.carbon.core.Project;
import icraf.carbon.gui.MenuFactory.MenuProperty;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class InputLandUsePanel extends JPanel {

	private static final long serialVersionUID = -5844291625397786356L;
	private LCListPanel lcListPanel = new LCListPanel();
	private Project project;
	private JTabbedPane tabPanel = new JTabbedPane();
	private MatrixPanel eligibilityPanel;
	private EligibilityTableModel eligibilityTable = new EligibilityTableModel();

	public InputLandUsePanel() {
		super();

		eligibilityPanel = new MatrixPanel(eligibilityTable, true, false, true,
				false, false);
		eligibilityPanel.getTable().setShowGrid(true);

		tabPanel.addTab(MenuProperty.PROJECT_LANDUSE_LIST.getLabel(), lcListPanel);
		tabPanel.addTab(MenuProperty.PROJECT_ELIGIBILITY.getLabel(), eligibilityPanel);
		tabPanel.addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent e) {
				if (tabPanel.getSelectedIndex() == 1) {
					eligibilityTable.setProject(project);
				}
			}
		});

		this.setLayout(new BorderLayout(5, 5));
		this.add(tabPanel, BorderLayout.CENTER);
	}

	public AbacusContainer getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
		lcListPanel.setProject(project);
		eligibilityTable.setProject(project);
	}

}
